﻿using CoreModule;
using System;
using System.Globalization;
using System.Windows.Data;

namespace ResourceLocalization.Converters
{
    /// <summary>
    /// 
    /// </summary>
    public class MeasurementValueToBloodGlucoseStatusTextConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var measurementValue = (double)value;

            var bloodGlucosePeriod = (CoreModule.BloodGlucosePeriod)parameter;

            var bloodGlucoseStatus = Extension.GetBloodGlucoseStatus(bloodGlucosePeriod, measurementValue);
             
            var text = string.Empty;

            if (bloodGlucoseStatus== BloodGlucoseStatus.LO)
            {
                return "LO";
            } 
            else if (bloodGlucoseStatus== BloodGlucoseStatus.HI)
            {
                return "HI";
            }

            switch (bloodGlucoseStatus)
            {
                case BloodGlucoseStatus.None:
                     text= WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("其他", null, null) + "";
                    break;
                case BloodGlucoseStatus.Other:
                     text = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("其他", null, null) + "";
                    break;
                case BloodGlucoseStatus.High:
                     text = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("偏高", null, null) + "";
                    break;
                case BloodGlucoseStatus.Low:
                     text = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("偏低", null, null) + "";
                    break;
                case BloodGlucoseStatus.Normal:
                     text = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject("正常", null, null) + "";
                    break;
                default:
                    return string.Empty; ;
            }
            return text;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
